package main_package;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Main 
{
	public static boolean isPart2 = false;
	
	public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue( Map<K, V> map )
	{
	    List<Map.Entry<K, V>> list =
	        new LinkedList<Map.Entry<K, V>>( map.entrySet() );
	    Collections.sort( list, new Comparator<Map.Entry<K, V>>()
	    {
	        public int compare( Map.Entry<K, V> o1, Map.Entry<K, V> o2 )
	        {
	            return (o2.getValue()).compareTo( o1.getValue() );
	        }
	    } );
	
	    Map<K, V> result = new LinkedHashMap<K, V>();
	    for (Map.Entry<K, V> entry : list)
	    {
	        result.put( entry.getKey(), entry.getValue() );
	    }
	    return result;
	}
	
	public static void main(String[] args)
	{
		if(args.length < 2)
		{
			System.out.println("Please enter two arguments: the name of the input file, the part number.");
			return;
		}
		String inputFileName = args[0];
		int partNo = Integer.parseInt(args[1]);
		isPart2 = (partNo == 2);
		
		// Insert all data about MT systems from the file
		Collection<MTSystem> mtSystems = new FileParser(inputFileName).Parse();
		HashMap<String,Double> nameBleuScoreMap = new HashMap<String, Double>();
		
		// Create a map of each system and its bleu score
		for(MTSystem mtSystem : mtSystems)
		{
			nameBleuScoreMap.put(mtSystem.GetName(), mtSystem.CalcBleuScore());
		}
		
		// Sort systems from highest bleu score to lowest
		Map<String,Double> sortedMtSystems = sortByValue(nameBleuScoreMap);
		
		for(String systemName : sortedMtSystems.keySet())
			System.out.println(systemName + "\t" + sortedMtSystems.get(systemName));
	}
}
